# Maintainer: Chris Gorman <chrisjohgorman@gmail.com>

_realname=castxml
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.6.11
pkgrel=2
pkgdesc="C-family abstract syntax tree XML output tool. (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/CastXML/CastXML'
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-clang-libs"
         "${MINGW_PACKAGE_PREFIX}-llvm-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-clang-tools-extra"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
source=(https://github.com/CastXML/CastXML/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('fc5b49f802b67f98ecea10564bc171c660020836a48cecefc416681a2d2e1d3d')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DCLANG_LINK_CLANG_DYLIB=1 \
      -DSPHINX_EXECUTABLE=${MINGW_PREFIX}/bin/sphinx-build \
      -DSPHINX_HTML=OFF \
      -DSPHINX_MAN=OFF \
      -DCastXML_INSTALL_DOC_DIR=share/doc/castxml \
      -DCastXML_INSTALL_MAN_DIR=share/man \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
